{extend name="$base" /}
{block name="resources"}
<script src="ADMIN_JS/art_dialog.source.js"></script>
<script src="ADMIN_JS/iframe_tools.source.js"></script>
<script src="ADMIN_JS/material_managedialog.js"></script>
<link rel="stylesheet" type="text/css" href="ADMIN_CSS/defau.css">
{/block}
{block name="main"}
<div class="set-style">
	<dl>
		<dt>图片：</dt>
		<dd>
			<div><p><img id="imgLogo"></p></div>
			<div class="upload-btn">
				<span>
					<input class="input-file" name="file_upload" id="uploadImg" type="file" onchange="imgUpload(this);">
					<input type="hidden"id="Logo" />
				</span>
				<p><i class="fa fa-cloud-upload"></i>上传图片</p>
			</div>
			<p class="hint"><br><span style="color:orange;">建议使用宽100像素-高100像素内的GIF或PNG透明图片；点击下方"提交"按钮后生效。</span></p>
		</dd>
	</dl>
	<dl>
		<dt>链接地址：</dt>
		<dd>
			<p><input id="link_url" type="text" class="input-common"></p>
			<p class="error">请输入链接地址</p>
		</dd>
	</dl>
	<dl>
		<dt>类型：</dt>
		<dd>
			<p><select id="type"><option value="0">PC端</option><option value="1">手机端</option></select></p>
			<p class="error">请选择类型</p>
		</dd>
	</dl>
	<dl>
		<dt>背景色：</dt>
		<dd>
			<p><input id="background" type="color" class="input-common-color"></p>
			<p class="error">请选择类型</p>
		</dd>
	</dl>
	<dl>
		<dt>排序：</dt>
		<dd>
			<p><input id="sort" type="text" class="input-common"></p>
			<p class="error">请输入序号</p>
		</dd>
	</dl>
	<dl>
		<dt></dt>
		<dd>
			<button class="btn-common btn-big" onclick="addShopAdAjax();">保存</button>
			<button class="btn-common-cancle btn-big" onclick="javascript:history.back(-1);" >返回</button>
		</dd>
	</dl>
</div>
<script src="__STATIC__/js/ajax_file_upload.js" type="text/javascript"></script>
<script src="__STATIC__/js/file_upload.js" type="text/javascript"></script>
<script>
//模块输入信息验证
function verify( ad_image,link_url){
	if(ad_image == ''){
		$("#ad_image").parent().next().show();
		return flase;
	}else{
		$(".error").hide();
	}
	if(link_url == ''){
		$("#link_url").parent().next().show();
		return flase;
	}else{
		$(".error").hide();
	}
}

//添加模块
function addShopAdAjax() {
	var ad_image = $("#Logo").val();
	var link_url = $("#link_url").val();
	var type = $("#type").val();
	var sort = $("#sort").val();
	var background = $("#background").val();
	verify(ad_image, link_url);
	$.ajax({
		type : "post",
		url : "{:__URL('ADMIN_MAIN/config/addshopad')}",
		data : {
			'ad_image' : ad_image,
			'link_url' : link_url,
			'type' : type,
			'sort' : sort,
			'background' : background,
		},
		success : function(data) {
			if (data["code"] > 0) {
				showMessage('success', "店铺广告添加成功","{:__URL('ADMIN_MAIN/config/shopadlist')}");
			}else{
				showMessage('error', "店铺广告添加失败");
			}
		}
	});
}

//图片上传
function imgUpload(event) {
	var fileid = $(event).attr("id");
	var data = { 'file_path' : "config" };
	uploadFile({
		url: __URL(ADMINMAIN + '/config/uploadimage'),
		fileId: fileid,
		data : data,
		callBack: function (res) {
			if(res.code){
				$("#imgLogo").attr("src",__IMG(res.data.path));
				$("#Logo").val(res.data.path);
				showTip(res.message,"success");
			}else{
				showTip(res.message,"error");
			}
		}
	});
}
</script>
{/block}